/*
 * @lc app=leetcode.cn id=152 lang=cpp
 *
 * [152] 乘积最大子数组
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int maxProduct(vector<int> &nums)
    {
        vector<vector<int>> dp(2, vector<int>(nums.size() + 1, 1));
        dp[0][0] = dp[1][0] = 1;
        int ans = nums[0];
        for(int i = 1; i <= nums.size(); i++)
        {
            dp[0][i] = max(dp[0][i-1] * nums[i-1], max(dp[1][i-1] * nums[i-1], nums[i-1]));
            dp[1][i] = min(dp[0][i-1] * nums[i-1], min(dp[1][i-1] * nums[i-1], nums[i-1]));
            ans = max(ans, max(dp[0][i], dp[1][i]));
        }


        return ans;
    }
};
// @lc code=end
